//
//  YMBaseViewController.swift
//  Driver
//
//  Created by lantaiyuan on 2017/9/21.
//  Copyright © 2017年 youmy. All rights reserved.
//  

import UIKit

class YMBaseViewController: UIViewController {

    /// 自定义导航条
    lazy var navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.cz_screenWidth(), height: 64))
    
    /// 自定义导航项，以后统一使用 navItem
    lazy var navItem = UINavigationItem()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    /// 重写 title 的 didSet 方法
    override var title: String? {
        didSet {
            navItem.title = title
        }
    }
}

extension YMBaseViewController{
    
    /// 设置UI
    fileprivate func setupUI(){
        
        view.backgroundColor = UIColor.cz_color(withHex: bg_color)
        
        setupNavigationBar()
        
    }
    
    /// 设置导航条
    private func setupNavigationBar() {
        // 添加导航条
        view.addSubview(navigationBar)
        // 将 item 设置给 bar
        navigationBar.items = [navItem]
        // 1> 设置 navBar 整个背景的渲染颜色
        navigationBar.barTintColor = UIColor.cz_color(withHex: 0x2ab650)
//        navigationBar.backgroundColor = UIColor.blue
        // 2> 设置 navBar 的字体颜色
        navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.darkGray]
        // 3> 设置系统按钮的文字渲染颜色
        navigationBar.tintColor = UIColor.orange
    }
}


// MARK: - 系统事件
extension YMBaseViewController {
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.window?.endEditing(true)
    }
}
